package arrdemo;

import java.util.Random;

public class arrTest5 {
    public static void main(String[] args) {
        /*
        需求：生成10个1-100之间的随机数存入数组
        1.求出所有数据和
        2.求所有数据的平均值
        3.统计有多少个数据比平均值小
         */

        int[] arr = new int[10];
        Random r = new Random();

        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100) + 1;
        }

        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];

        }
        int avg = sum / arr.length;
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < avg) {
                count++;
            }
        }

        System.out.println("和是" + sum);
        System.out.println("平均值是" + avg);
        System.out.println("比平均值小的数有" + count + "个");

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
